package com.hzit.auth.client.factory;

import com.hzit.common.util.R;
import com.hzit.common.util.User;
import com.hzit.auth.client.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：远程调用的熔断处理
 */
@Component
@Slf4j
public class HzitFallbackFactory implements FallbackFactory<UserClient> {
	@Override
	public UserClient create(Throwable cause) {
		return new UserClient() {
			@Override
			public R<User> findUserByUsername(String username) {
				log.info("根据用户名查询用户信息失败！");
				return R.fail("根据用户名查询用户信息失败！");
			}

			@Override
			public R<List<String>> findPermissionsByUsername(String username) {
				log.info("根据用户名查询用户权限列表失败！");
				return R.fail("根据用户名查询用户权限列表失败！");
			}
		};
	}
}
